package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.StrategyCatalogQuery;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;


    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") StrategyCatalogQuery qo){

        PageInfo<?> query = strategyCatalogService.query(qo);
        model.addAttribute("pageInfo",query);
        model.addAttribute("stragegies",strategyService.listAll());
        return "strategy/catalog";
    }




    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(StrategyCatalog strategy){

        strategyCatalogService.saveOrUpdate(strategy);
        return new JSONResult();
    }


    @RequestMapping("allByStrategyId")
    @ResponseBody
    public Object allByStrategyId(Long strategyId){
        return strategyCatalogService.allByStrategyId(strategyId);
    }
}
